/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rw.table.formatter;

import java.text.ParseException;
import javax.swing.SwingConstants;

/**
 *
 * @author Rene Tapia
 */
public class IntegerCellFormatter implements ICellFormatter {

    private int align;

    public IntegerCellFormatter() {
        this(SwingConstants.RIGHT);
    }

    public IntegerCellFormatter(int align) {
        this.align = align;
    }

    @Override
    public String format(Object value) {
        int intValue = ((Integer) value).intValue();
        return Integer.toString(intValue);
    }

    @Override
    public Object parse(String strValue) throws ParseException {
        try {
            return Integer.parseInt(strValue);
        } catch (NumberFormatException e) {
            throw new ParseException(strValue, 0);
        }
    }

    @Override
    public int getAlign() {
        return align;
    }
}
